function deptPage(p){
		$.ajax({
			url : "dept/loadDept.sls",
			type : "post",
			data : {"page":p},
			dataType : "json",
			success : function(result) {
				$("#dept_tbody").empty();
				if(result.status == 0){
					var depts = result.data;
					for(var i=0;i<depts.length;i++){
						var deptId = depts[i].deptId;
						var deleteElement = '<a href="javascript:dept_delet('+deptId+');" class="ico del">解散</a>';
						if(deptId == '1' || deptId == '0'){
							deleteElement = '';
						}
						var s = '<tr><td><a style="text-decoration: none;" href="javascript:dept_detail('+deptId+')">'+depts[i].dName+'</a></td><td>'+
						depts[i].dEmps+'</td>'+
						'<td>'+depts[i].descr+'</td>'+
						'<td>'+deleteElement+'</td>'+
						'</tr>';
						
						var $tr = $(s);
						$tr.data("deptId",deptId);
						$("#dept_tbody").append($tr);
					}

					$.ajax({
						url : "dept/deptPage.sls",
						type : "post",
						dataType : "json",
						success : function(result) {
							if(result.status == 0 ){
								var page = result.data.page;
								var total = result.data.total;
								var top ;
								var end ;
								var pageBody = "";
								if(page == 1){
									top = '<a>上一页</a>';
								} else {
									top = '<a href="javascript:deptPage('+(page-1)+');">上一页</a>';
								}
								if(page == total){
									end = '<a>下一页</a>';	
								} else {
									end = '<a href="javascript:deptPage('+(page+1)+');">下一页</a>';
								}
								var i=1;
								var m=3;
								if(page>1){
									i = page-1;
									m = page+1;
								}
								if(m>total){
									i--;
									m = total;
								}
								if(i==0){
									i=1;
								}
								for(i;i<=m;i++){
									if(i==page){
										pageBody+='<a href="javascript:deptPage('+i+');" style="font-weight:bold;color:#8d341f;">'+i+'</a>';
									} else {
										pageBody+='<a href="javascript:deptPage('+i+');">'+i+'</a>';
									}
								}
								var s = top+pageBody+end;									
								$("#dept_page").html(s);
							}
						},
						error : function(){
							window.location.href="error.sls";
						}
					});
				}
				
			},
			error : function(){
				window.location.href="error.sls";
			}
		});
}

function dept_delet(deptId){
	var ok = confirm("确定要解散此部门吗?");
	if(ok){
	$.ajax({
		url : "dept/deleteDept.sls",
		type : "post",
		data : {"id":deptId},
		dataType : "json",
		success : function(result) {
			if(result.status == 0){
				deptPage(result.data);
			} 
			if(result.status == 2){
				$("#dept_error").show();
				setTimeout(function(){$("#dept_error").hide();},1000);
			}
		},
		error : function(){
			window.location.href="error.sls";
		}
	});
	}
}

function dept_detail(deptId){
	window.location.href = "toEmp.sls?deptId="+deptId;
}



